package object5.library.operation;

import object5.library.Book;
import object5.library.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("归还书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书籍编号: ");
        int id = scanner.nextInt();
        if(id < 0||id >= bookList.getSize()){
            System.out.println("输入的编号无效");
            return;
        }
        Book book = bookList.getBook(id);
        if(!book.isBorrowed()){
            System.out.println("该书籍未借出,不能归还");
            return;
        }
        book.setBorrowed(false);
        System.out.println("归还成功");
    }
}
